#include"game.h"
void InitBoard(char board[hangs][lies], int hs, int ls, char set)
{
	int i;
	for (i = 0; i < hs; i++)
	{
		int j;
		for (j = 0; j < ls; j++)
		{
			board[i][j] = set;
		}
	}
}
void PrintBoard(char show[hangs][lies], int h, int l)
{
	int i;
	for (i = 0; i <= l; i++)
	{
		printf("%d ", i);
	}
	printf("\n");
	for (i = 1; i <= h; i++)
	{
		printf("%d ", i);
		int j;
		for (j = 1; j <= l; j++)
		{
			printf("%c ", show[i][j]);
		}
		printf("\n");
		
	}
}
void SetMine(char board[hangs][lies], int h, int l)
{
	int count = easy_count;
	srand((unsigned int)time(NULL));
	while (count)
	{
		int a = rand() % h + 1;
		int b = rand() % l + 1;
		if (board[a][b] == '0')
		{
			board[a][b] = '1';
			count--;
		}
	}
}
int show_how_many_mines(char mine[hangs][lies], int h, int l)
{
	return (mine[h - 1][l - 1] + mine[h - 1][l] + mine[h - 1][l + 1] + mine[h][l - 1] + mine[h + 1][l - 1] + mine[h][l + 1]
		+ mine[h + 1][l] + mine[h + 1][l + 1]) - 8 * '0';
}
void FindMine(char mine[hangs][lies], char show[hangs][lies], int h, int l)
{
	int win = hang * lie - easy_count;
	while (win)
	{
		printf("please input the crood :");
		scanf_s("%d %d", &h, &l);
		if (h >= 1 && h <= hang && l >= 1 && l <= lie)
		{
			if (mine[h][l] == '1')
			{
				printf("BOMB! YOU DIE!\n");
				PrintBoard(mine, hang, lie);
				break;
			}
			else
			{
				int c = show_how_many_mines(mine, hang, lie);
				show[h][l] = c + '0';
				PrintBoard(show, hang, lie);
				win--;
			}printf("\n");
		}
		else
		{
			printf("crood is out of the range!!!!\n");
		}
	}
	if (win == 0)
	{
		printf("YOU WIN!!!\n");
	}
}